﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SzCourt.WebSite
{
    public class AdminSession
    {
          public class SessionBox
        {
            private SessionBox() { }

            #region 用户Session操作

            /// <summary>
            /// 檢測User Session是否存在
            /// </summary>
            /// <returns></returns>
            public static bool CheckUserSession()
            {
                object o = System.Web.HttpContext.Current.Session["ADMINUSER"];
                if (o == null)
                    return false;
                else
                    return true;

            }

            /// <summary>
            /// 登记User Session
            /// </summary>
            /// <param name="userinfo"></param>
            public static void CreateUserSession(AdminUserSession userinfo)
            {
                System.Web.HttpContext.Current.Session["ADMINUSER"] = userinfo;
            }

            /// <summary>
            /// 获取User Session
            /// </summary>
            /// <returns></returns>
            public static AdminUserSession GetUserSession()
            {
                object o = System.Web.HttpContext.Current.Session["ADMINUSER"];
                if (o == null) throw new ExceptionAdminSession("读取UserSession失败。");
                else return (o as AdminUserSession);
            }

            /// <summary>
            /// 移除User Session
            /// </summary>
            public static void RemoveUserSession()
            {
                object o = System.Web.HttpContext.Current.Session["USER"];
                if (o != null) System.Web.HttpContext.Current.Session.Remove("User");
            }

            #endregion


            //#endregion
        }


    }
    /// <summary>
    /// 丢失Session异常。
    /// </summary>
    public class ExceptionAdminSession : Exception
    {
        public ExceptionAdminSession() : base() { }
        public ExceptionAdminSession(string message) : base(message) { }
        public ExceptionAdminSession(string message, Exception inner) : base(message, inner) { }
    }
    public class AdminUserSession
    {
        /// <summary>
        /// 初始化用户登录Session
        /// </summary>
        /// <param name="_loginId">用户ID</param>
        /// <param name="_loginname">用户名</param>
        /// <param name="_roleid">角色ID</param>
        /// <param name="_groupid">分组ID</param>
        /// <param name="_islimit">是否授权限限制</param>
        /// <param name="_status">用户状态</param>
        public AdminUserSession(string _username, System.Guid _userguid, string _deptname)
        {

            this.UserName = _username;
            this.UserGUID = _userguid;
            this.DeptName = _deptname;
        }


        public string UserName;
        public System.Guid UserGUID;
        public string DeptName;
    }
    
}